package com.javafactroy.kunlong.dxp.manager.web;


import app.dto.JsonResult;
import com.baomidou.lock.annotation.Lock4j;
import com.javafactroy.kunlong.dxp.manager.service.iface.LockService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
// https://blog.csdn.net/ww2651071028/article/details/129579555

@Slf4j
@RestController
@RequestMapping("/dxp")
public class LockManagerController {
    
    @Autowired
    LockService lockService;

    @GetMapping("/lockMethod")
    @Lock4j(keys = {"#key"}, acquireTimeout = 1000, expire = 10000)
    public JsonResult lockMethod(@RequestParam String key) {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return JsonResult.success(key);
    }


    @GetMapping("/lockMethod1")
    @Lock4j(keys = {"#key"}, acquireTimeout = 1000, expire = 10000)
    public JsonResult lockMethod1(@RequestParam String key) {
        lockService.lock(key);
        return JsonResult.success(key);
    }
}